<?php
/**
 * Created by PhpStorm.
 * User: W
 * Date: 2018/2/24
 * Time: 16:57
 */

namespace app\console\controller;

use app\common\controller\Common;

class Login extends Common {

    public function index() {
        if (request()->isPost()) {
            $login = request()->post('login');
            $password = request()->post('password');
            cookie('login', $login);
            $admin_info = model('Admins')->where('username', $login)->find();
            if (!$admin_info) {
                $this->error("无法识别的账号。");
            }
            if (false === password_verify($password, $admin_info['password'])) {
                $this->error("密码与账号不匹配。");
            }
            session('admin_session', $admin_info['id']);
            $this->redirect(url('index/index'));
        } else {
            $this->assign('login', cookie('login'));
            return $this->fetch();
        }
    }

}
